# Maintainer: David Runge <dvzrv@archlinux.org>

_name=mailman
pkgname=mailman3
pkgver=3.3.8
_commit=f06d9adae8e297798113f67ecda43145b23c7747  # refs/tags/3.3.8
pkgrel=2
pkgdesc="The GNU mailing list manager"
arch=(any)
url="https://www.list.org/"
license=(GPL3)
depends=(
  gunicorn
  python-aiosmtpd
  python-alembic
  python-atpublic
  python-authheaders
  python-authres
  python-click
  python-dateutil
  python-dnspython
  python-falcon
  python-flufl.bounce
  python-flufl.i18n
  python-flufl-lock
  python-importlib_resources
  python-lazr.config
  python-passlib
  python-requests
  'python-sqlalchemy>=1.4'
  python-zope-component
  python-zope-configuration
  python-zope-event
  python-zope-interface
)
makedepends=(git python-build python-installer python-setuptools python-wheel)
checkdepends=(python-flufl.testing python-nose2 python-psycopg2
python-pymysql python-pytest)
optdepends=(
  'hyperkitty: for local archive and list interaction'
  'lynx: for the default HTML to plaintext conversion'
  'mailman3-hyperkitty: for archiving mails with an instance of hyperkitty'
  'postorius: for local configuration interaction'
  'python-mailmanclient: for programmatically interfacing the mailman REST API locally'
  'python-psycopg2: for PostgreSQL support'
  'python-pymysql: for MySQL support'
  'smtp-server: for using a local mail server'
)
conflicts=(mailman)
replaces=(mailman-core)
backup=(etc/mailman.cfg)
source=(
  $pkgname::git+https://gitlab.com/$_name/$_name#tag=$_commit?signed
  $pkgname.service
  $pkgname-digests.service
  $pkgname-digests.timer
  $pkgname-gatenews.service
  $pkgname-gatenews.timer
  $pkgname-notify.service
  $pkgname-notify.timer
  $pkgname.sysusers
  $pkgname.tmpfiles
)
sha512sums=('SKIP'
            '5773eae02dee11b83eb73ba81bca98d9d0a22fa3175d53172d17bbc0e9821360a4d562b6f42a3bb55c2f0c0b5b50ab84ee82da4cf8b3ff38555a378687dcde3c'
            'dccb7bfac560252f6c36ce26149d72d7faa52c1ff283b725deab802b0a94c45692224936b1a099b95dd5d90782dd39ecb15e299303d0264f1c14a6ac8052ee77'
            '5d7ccba8cf1262ab052078f2188ded15e43e1201302c7c24ce763efef9789ec99d8ea9a19e8fbd9bc5a38f47a162fe5cf4b0ade284894cb57af66350f23507bc'
            'f02f0c25c5eb3493a4d345783a41a7ef03b9b4265b09bc5dc5d3cd6749c51f10d6d9f2b3fb48435df932008cf02b6b28ee28951e1e8db195ed5ef7eb3e32f7c6'
            'fc550ef017ad8a22e0c40a8808361831b8c32cd0d34925cdce433ec4a0564e9577d6f9ccdcd38098eb4cf692257c061ff3fbea3b762d274f9b5e2fa88d10d82e'
            'edc14e009d117c9799bb5d20f0f81dd580acdc184c35cbaf6596056467bc3116d77e5e4a1d9957cf23201cfd57c3a82970fe996e0565c8e527d83fcfc132051a'
            'b8538618be8bdd6313d24b844d15c8f25a059c3391cd06db69314b7be19996bfbe913d6c0c9c99d6a19c4f92df32212d31785e92fb32faf5eb792fffe121fcce'
            '074cf58a93204d4b7631c4cc8af62d5720560301c6fefef6baa5d3aa33e72720870757fac7803f7b2835f8f02bb776f9d049df5c7528c743b56dda7da2085b07'
            '6f4b51fd5eb34ac974b3312c34eb1437d9435cfd50f0cb89db02b94ce514bceca2c6dc7cb172b79b2d6a23d68e7ea391ec58dbd9899938c0fe88c03c67c521b9')
b2sums=('SKIP'
        '3efaa4559bcf54b322f4a21ee3000f5b2bea72dad2f9f436967f5c4d4ed8046bc08f8e31457991e63252237134f3f7d2f9e7e7862ebc211aeef11d506ded4440'
        'fc6d6545dad6cecfd4c1197269a3ec025eb0b830e04151bb2dee778b9e357127667c5a65ea401b10e31e2ec6a8509719de29c30471fa50d09634c934bdf50b9b'
        'b0d764dd4f7017c2d5b76e8a52b0c8d75e35b0b0d9025609853d389f8fa0732ea902549ef168f988bf845370cf67aeb7d439af8dec1997127522055b11e64000'
        '62dffd34e9952b5b7430b55d2ed01aafa8023b48d679f06cdaf444180012b8766ff633f198b92eade228420bad40718bc98f156b0c86a0f29e224585ccec48e0'
        '06bfa99d6356efc426430b67de9ed18bd80a5d659b4f0c81d7e2306810c856d1de34c5df1fd2834228f3c2b78fc42806f1d9bede9ddb3ac7185a367608c0a823'
        'ca8aca1a916e99ed313adfd57c33fdd7a3e1b883e22daae8a1e32084331aa32e7ab99b8adfb6ef95b8b696232d044c65de23dba28b2c7e31a9bd02a5f2cb22c2'
        'b980470b16171ed0e32a0c1d9de7d5e6802431dd5275089c03f7bc862d5ac886b78af8aa8828faa71a63e847c9caf660c3da2890828ecb2e0bea537c2c4001a5'
        '594d6a6712f9e817f4d935225d3a1d87c96e23f1e449caab6bfb00ce2a0421af1401505c6d1d280a03f8c551136639f0dabf27d8b549ca4ea26bdb3febdda660'
        '461dce577696405011ed89f7fc109caaf27f4183b4d315baa8ad03db0f12015ebc447cbe9c0b8c5bcba38b63fcaf45adcfcb3e5bf5afb7eb0bd87a2e1b0301e5')
validpgpkeys=('541EA0448453394FF77A0ECC9D9B2BA061D0A67C') # Abhilash Raj <maxking@asynchronous.in>

prepare() {
  cd $pkgname
  # make sure that mailman runs in a FHS compliant way
  printf "[mailman]\nlayout: fhs\n" >> ../$_name.cfg
  # set /var/lib/mailman instead of /var/tmp/mailman as default var_dir:
  sed -e 's|/var/tmp/mailman|/var/lib/mailman|g' -i src/$_name/config/schema.cfg
}

build() {
  cd $pkgname
  python -m build --wheel --no-isolation
}

check() {
  cd $pkgname
  # thanks to test design it is impossible to run tests:
  # https://gitlab.com/mailman/mailman/-/issues/400
  # nose2 -v
}

package() {
  cd $pkgname
  python -m installer --destdir="$pkgdir" dist/*.whl

  # config
  install -vDm 640 ../$_name.cfg -t "$pkgdir/etc/"
  # state dir
  install -vdm 750 "$pkgdir/var/lib/mailman"
  # sysusers.d
  install -vDm 644 ../$pkgname.sysusers "$pkgdir/usr/lib/sysusers.d/$pkgname.conf"
  # tmpfiles.d
  install -vDm 644 ../$pkgname.tmpfiles "$pkgdir/usr/lib/tmpfiles.d/$pkgname.conf"
  # services and timer
  install -vDm 644 ../*.{service,timer} -t "$pkgdir/usr/lib/systemd/system"
}
